package utils

import adapters.Fruit
import com.liugl.recyclerviewtest.R

object DataUtil {
    fun getFruitList(auto: Boolean = false): ArrayList<Fruit> {
        val names = listOf(
            "Apple",
            "Banana",
            "Orange",
            "Watermelon",
            "Pear",
            "Grape",
            "Pineapple",
            "Strawberry",
            "Cherry",
            "Mango",
        )


        val images = listOf(
            R.drawable.apple_pic,
            R.drawable.banana_pic,
            R.drawable.orange_pic,
            R.drawable.watermelon_pic,
            R.drawable.pear_pic,
            R.drawable.grape_pic,
            R.drawable.pineapple_pic,
            R.drawable.strawberry_pic,
            R.drawable.cherry_pic,
            R.drawable.mango_pic,
        )

        val fruitList = ArrayList<Fruit>()

        if (auto) {
            val longNames = ArrayList<String>()
            names.forEach { s: String -> longNames.add(getRandomLengthString(s)) }
            repeat(10) {
                fruitList.add(Fruit(longNames[0], images[0]))
                fruitList.add(Fruit(longNames[1], images[1]))
                fruitList.add(Fruit(longNames[2], images[2]))
                fruitList.add(Fruit(longNames[3], images[3]))
                fruitList.add(Fruit(longNames[4], images[4]))
                fruitList.add(Fruit(longNames[5], images[5]))
                fruitList.add(Fruit(longNames[6], images[6]))
                fruitList.add(Fruit(longNames[7], images[7]))
                fruitList.add(Fruit(longNames[8], images[8]))
                fruitList.add(Fruit(longNames[9], images[9]))
            }

            return fruitList
        }



        repeat(10) {
            fruitList.add(Fruit(names[0], images[0]))
            fruitList.add(Fruit(names[1], images[1]))
            fruitList.add(Fruit(names[2], images[2]))
            fruitList.add(Fruit(names[3], images[3]))
            fruitList.add(Fruit(names[4], images[4]))
            fruitList.add(Fruit(names[5], images[5]))
            fruitList.add(Fruit(names[6], images[6]))
            fruitList.add(Fruit(names[7], images[7]))
            fruitList.add(Fruit(names[8], images[8]))
            fruitList.add(Fruit(names[9], images[9]))
        }

        return fruitList
    }

    private fun getRandomLengthString(s: String): String {
        val n = (1..20).random()
        val builder = StringBuilder()
        repeat(n) {
            builder.append(s)
        }

        return builder.toString()
    }
}